

#include <stdint.h>
#include "error_code.h"
#include "connector.h"
#include "base.h"

#include "ConRaw.h"


/*
检测卡是否插入
返回:
	非零——卡插入
	零——卡没有插入
*/

uint8_t Connector_CheckCardPresent(connector_t *con, uint8_t slot_num)
{        
	if(con->method->checkPresent){
		return con->method->checkPresent(con, slot_num);
	}
	return 0;
}

uint8_t Connector_PowerUp(connector_t *con, uint8_t voltage)
{	
	if(con->method->setVCC){
		return con->method->setVCC(con, voltage);
	}
	return 0;
}

void Connector_PowerDown(connector_t *con)
{
	if(con->method->setVCC){
		con->method->setVCC(con, 0);
	}
}

uint8_t Connector_SetVCC(connector_t *con, uint8_t voltage)
{
	if(con->method->setVCC){
		return con->method->setVCC(con, voltage);
	}
	return 0;
}

void Connector_SetResetHigh(connector_t *con)
{
	if(con->method->setReset){
		con->method->setReset(con, CON_HIGH);
	}
}

void Connector_SetResetLow(connector_t *con)
{
	if(con->method->setReset){
		con->method->setReset(con, CON_LOW);
	}
}

void Connector_SetResetState(connector_t *con, uint8_t state)
{
	if(con->method->setReset){
		con->method->setReset(con, state);
	}
}

void Connector_Switch(connector_t *con, uint8_t num)
{
	if(con->method->switchTo){
		con->method->switchTo(con, num);
	}
}

void Connector_ClockActive(connector_t *con)
{
	if(con->method->configClock){
		con->method->configClock(con, CON_CLK_TRANSPARENT);
	}
}

void Connector_ClockDeactive(connector_t *con)
{
	if(con->method->configClock){
		con->method->configClock(con, CON_CLK_BIT_LOW);
	}
}

uint8_t Connector_ConfigClock(connector_t *con, uint8_t conf)
{
	if(con->method->configClock){
		return con->method->configClock(con, conf);
	}
	return 0;
}

uint8_t Connector_SetClockState(connector_t *con, uint8_t state)
{
	if(con->method->setClock){
		con->method->setClock(con, state);
	}
	return 0;
}

uint8_t Connector_ConfigIO(connector_t *con, uint8_t conf)
{
	if(con->method->configIO){
		return con->method->configIO(con, conf);
	}
	return 0;
}

uint8_t Connector_SetIOState(connector_t *con, uint8_t state)
{
	if(con->method->setIO){
		con->method->setIO(con, state);
	}
	return 0;
}

uint8_t Connector_GetIOState(connector_t *con, uint8_t *state)
{
	if(con->method->getIO){
		return con->method->getIO(con);
	}
	return 0;
}

uint8_t Connector_GetInState(connector_t *con)
{
	return 0;
}


uint8_t Connector_SetC4State(connector_t *con, uint8_t state)
{
	if(con->method->setC4){
		con->method->setC4(con, state);
	}
	return 0;
}

uint8_t Connector_SetC8State(connector_t *con, uint8_t state)
{
	if(con->method->setC4){
		con->method->setC4(con, state);
	}
	return 0;
}

void Connector_Init(void)
{
	ConRaw_Init();
}

connector_t* Connector_Get(uint8_t num){
	return ConRaw_Get(num);
}



